package com.zmzncs.lmtc.module.promotion.pojo.reserve_rule;

import com.zmzncs.lmtc.common.util.ExceptionUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 
 * </p>
 *
 * @author 高博文
 * @since 2020-08-12
 */
@Data
public class ReserveRuleUpdateForm implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id", required = true)
    @NotNull
    private Long id;

    @ApiModelProperty(value = "规则名称", required = true)
    @NotBlank
    private String ruleName;

    @ApiModelProperty(value = "是否所有停车场（1：是，0否）", required = true)
    @NotNull
    private Integer ifAllParks;

    @ApiModelProperty(value = "停车场id", required = true)
    private List<Long> parkIds;

    @ApiModelProperty(value = "时段费用", required = true)
    private List<TimeSlot> timeSlotList;

    @Data
    public static class TimeSlot{

        @ApiModelProperty(value = "时段开始时间(时分秒)", required = true)
        private String reserveBeginTime;

        @ApiModelProperty(value = "时段结束时间(时分秒)",required = true)
        private String reserveEndTime;

        @ApiModelProperty(value = "预约金额", required = true)
        private BigDecimal amount;
    }


    public void validate(){
        //  当选择部分停车场时，parkIds不能为空
        if(!(ifAllParks.equals(0) && parkIds != null && !parkIds.isEmpty())){
            ExceptionUtil.paramException("当选择部分停车场时，parkIds不能为空");
        }
        //  校验ifAllParks
        if(!(ifAllParks.equals(0) || ifAllParks.equals(1))){
            ExceptionUtil.paramException("ifAllParks取值范围（1：是，0否）");
        }
        //  校验支付金额
        if(parkIds == null || parkIds.isEmpty()){
            ExceptionUtil.paramException("预约时段费用必须有一个");
        }
    }




}
